<template>
  <div class="content">
    <div class="pageSearchView">
      <SearchForm v-model="searchParam" :fields="searchFields" :handleSearch="handleSearch"/>
    </div>

    <div class="pageTableView">
      <el-tabs v-model="activeName" type="card" class="demo-tabs" @tab-click="handleClick">
        <el-tab-pane label="未完成" name="CREATED">

          <div class="pageTableMenuView">
            <div class="pageTableTitle">
              保养列表信息
              <el-icon>
                <house-icon/>
              </el-icon>
            </div>
          </div>
          <Unfinished :paginationParams="paginationParams" :pageTotal="pageTotal" :taskNoPage="taskNoPage"
                      :onSubmit="onSubmit" :fetchPage="fetchPage" :equipmentData="equipmentData"
                      :handleSizeChange="handleSizeChange" :handleCurrentChange="handleCurrentChange"/>
        </el-tab-pane>
        <el-tab-pane label="已完成" name="FINISHED">
          <div class="pageTableMenuView">
            <div class="pageTableTitle">
              列表信息
              <el-icon>
                <house-icon/>
              </el-icon>
            </div>
          </div>
          <Finish :paginationParams="paginationParams" :pageTotal="pageTotal" :taskNoPage="taskNoPage"
                  :onSubmit="onSubmit" :fetchPage="fetchPage" :equipmentData="equipmentData"
                  :handleSizeChange="handleSizeChange" :handleCurrentChange="handleCurrentChange"/>
        </el-tab-pane>

      </el-tabs>

    </div>


  </div>
</template>

<script setup>
import SearchForm from '@/components/SearchForm.vue';
import {useToolData} from '@/hooks/baseData/tooling';
import axiosInstance from "@/utils/http/api";
import {Delete, Edit, Plus} from '@element-plus/icons-vue';
import {ElMessage, ElMessageBox} from 'element-plus'; // 假设使用 Element Plus
import {computed, onMounted, ref} from 'vue';
import Unfinished from './unfinished.vue'
import Finish from './finish.vue'
import {equipmentAll, equipmentInspectionTaskPage, equipmentInspectionTaskUpdate} from '@/api/device/pointInspection'

const activeName = ref('CREATED')
const searchParam = ref({})
const searchFields = ref([
  {
    name: "name",
    label: "计划名称",
    component: "input",
    placeholder: "",
    class: "!w-[350px]",
  },

])
const pageTotal = ref(0)
const taskNoPage = ref([])
const equipmentData = ref([])
const paginationParams = ref({pageSize: 10, current: 1})
onMounted(() => {
  fetchPage()
  fetchAll()

});
const fetchAll = () => {
  equipmentAll({}).then(res => {
    equipmentData.value = res.data
  })
}
const fetchPage = () => {
  console.log(activeName.value, 'activeName.value')
  let statusList = ['EXECUTING', 'CREATED']
  if (activeName.value === 'FINISHED') {
    statusList = ['FINISHED']
  }
  equipmentInspectionTaskPage({
    ...paginationParams.value,
    ...searchParam.value,
    statusList,
    equipmentInspectionType: 1,
    type: 1,
  }).then(res => {
    console.log(res)
    taskNoPage.value = res.data.records
    pageTotal.value = res.data.total

  })
}
const handleSearch = () => {
  fetchPage()

}
const handleClick = (tab, event) => {
  activeName.value = tab.props.name
  fetchPage()
}
const onSubmit = (params, callback) => {
  equipmentInspectionTaskUpdate(params).then(res => {
    if (res.code === 200) {
      ElMessage.success('操作成功');
      fetchPage()
      callback();
    } else {
      ElMessage.error(res.message);
    }
  })

}

const handleSizeChange = (val) => {
  paginationParams.value.pageSize = val;
  fetchPage()
}
const handleCurrentChange = (val) => {
  paginationParams.value.current = val;
  fetchPage()
}

</script>

<style scoped></style>
